home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / amiga / v3_1 / sbp3_1e.lzh / MATHMENU.PL < prev    next >
Text File  |  1991-10-31  |  1KB  |  37 lines

  1. /* From the book PROLOG PROGRAMMING IN DEPTH
  2.    by Michael A. Covington, Donald Nute, and Andre Vellino.
  3.    Copyright 1988 Scott, Foresman & Co.
  4.    Non-commercial distribution of this file is permitted. */
  5. /* Modified for Quintus Prolog by Andreas Siebert */
  6.  
  7. /* MATHMENU.PL */
  8. /* Demonstrates using a menu to choose an operator and
  9.    then build an arithmetic expression around it */
  10.  
  11. /* Requires procedure READNUMBER defined in READNUM.PL */
  12. :- ( clause(readnumber(_),_) ; consult('readnum.pl') ).
  13.  
  14. /* Requires procedure MENU defined in MENU.PL */
  15. :- ( clause(menu(_,_),_) ; consult('menu.pl') ).
  16.  
  17. go :- write('Enter two numbers.'),nl,
  18.       write('The first number:   '),
  19.       readnumber(Num1),
  20.       nl,
  21.       write('The second number:  '),
  22.       readnumber(Num2),
  23.       nl,
  24.       write('Choose an operation: '),nl,
  25.       menu([item('Add','+'),
  26.             item('Subtract','-'),
  27.             item('Multiply','*'),
  28.             item('Divide','/')],
  29.            Operation),
  30.       E =.. [Operation,Num1,Num2],
  31.       write('We have constructed the expression: '),
  32.       write(E),
  33.       nl,
  34.       call(V is E),
  35.       write('It evaluates to: '),
  36.       write(V).
  37.